package ewgenius.xube.engine.graphics.gui;

import java.awt.Font;
import java.awt.FontFormatException;
import java.io.IOException;
import java.io.InputStream;

import org.lwjgl.util.Color;
import org.lwjgl.util.Rectangle;
import org.lwjgl.util.vector.Vector2f;
import org.newdawn.slick.TrueTypeFont;
import org.newdawn.slick.util.ResourceLoader;

import ewgenius.xube.XubeEngine;
import ewgenius.xube.engine.graphics.*;

public class Window extends Gui {

	protected String title;
	protected int borderWidth = 3;
	protected int titleHeight = 22;
	protected Color backgroundColor = new Color(Color.GREY);
	protected Color borderColor = new Color(Color.LTGREY);
	protected Color shadowColor = new Color(Color.DKGREY);

	protected Vector2f innerPosition = new Vector2f();

	protected Vector2f getInnerPosition() {
		getPosition();
		innerPosition = new Vector2f(position.x + borderWidth, position.y
				+ borderWidth);
		return innerPosition;
	}

	public Window(int width, int height, String title) {
		this.width = width;
		this.height = height;
		this.title = title;
		getPosition();
		activeArea.setX((int) position.x);
		activeArea.setY((int) position.y + height - titleHeight);
		activeArea.setWidth(width);
		activeArea.setHeight(titleHeight);

		Button button = new Button(16, 16, this);
		button.setLocation(new Vector2f(width - 20, height - 20));
		this.children.add(button);
	}

	public void render(Render render) {
		getPosition();
		getInnerPosition();

		render.draw2DRect(new Vector2f(position.x - 1, position.y - 1),
				width + 2, height + 2, shadowColor);

		render.draw2DRect(position, width, height, borderColor);

		render.draw2DRect(innerPosition, width - 2 * borderWidth, height
				- titleHeight - 2 * borderWidth, backgroundColor);
		//render.draw2DString(title, activeArea.getX(), activeArea.getY());
		for (Gui gui : children) {
			gui.render(render);
		}
	}

	public void update(int time, XubeEngine engine) {
		getPosition();
		getInnerPosition();

		drag(engine);
	}
}
